﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Forms;

namespace MetaDemo.Forms
{
    public partial class ObjectInfoForm : Form
    {

        public static Form Get(Object o)
        {
            var form = Initialize(o);
            form.AddObjectTabs(o);
            return form;
        }

        public static Form Get(Assembly a)
        {
            var form = Initialize(a);
            form.AddObjectTabs(a);
            form.AddAssemblyTabs(a);

            form.Text += ": \"" + a.GetName().Name + "\"";
            return form;
        }

        public static Form Get(Control c)
        {
            var form = Initialize(c);
            form.AddObjectTabs(c);

            if (null != c.Text && 0 < c.Text.Length)
                form.Text += ": \"" + c.Text.Substring(0, Math.Min(20, c.Text.Length)) + "\"";
            return form;
        }

        private static ObjectInfoForm Initialize(Object o)
        {
            var form = new ObjectInfoForm();
            form.Text = o.GetType().Name;
            return form;
        }



        public ObjectInfoForm()
        {
            InitializeComponent();
        }

        private void AddAssemblyTabs(Assembly a)
        {
            tctContent.Controls.Add(Tabs.AssemblyMetrics.Get(a));
        }

        private void AddObjectTabs(Object o)
        {
            tctContent.Controls.Add(Tabs.ObjectIntroduction.Get(o));
            tctContent.Controls.Add(Tabs.ObjectFields.Get(o));
            tctContent.Controls.Add(Tabs.ObjectProperties.Get(o));
            tctContent.Controls.Add(Tabs.ObjectMethods.Get(o));

            // TODO 29 PoC
            Console.WriteLine(o.GetType().Assembly.FullName);
            if (o is ToolStrip && Program.program_path.EndsWith("mageui.exe"))
            {
                tctContent.Controls.Add(Tabs.Todo29Tab.Get(o as ToolStrip));
            }
        }

        private void tctContent_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}
